<?php
use \PsiFramework\Classes\Util\UI\Printer;
use \PsiFramework\Classes\Util\UI\HTML;
use \PsiFramework\Classes\Util\Log\Logger;

$category = $response->getAttribute("object");
$objectType = $response->getAttribute("objectType");
?>
<form
    class="editForm"
    method="POST"
    action="<?php Printer::display(HTML::linkHref('action=CMS.Save&type='.$objectType));?>">
    <?php
    if ($category != null) {
    ?>
    <input
        type="hidden"
        name="id"
        value="<?php Printer::display($category->getId()); ?>" />
    <?php
    }
    ?>
    <div class="label">
        <span class="titre">Nom :</span>
        <input
            class="firstInput"
            type="text"
            name="name"
            value="<?php if ($category != null) Printer::display($category->getName()); ?>" />
    </div>
    <div class="label">
        <span class="titre">Description :</span>
        <textarea
            class="firstInput"
            type="text"
            name="description" ><?php
            if ($category != null) {
                Printer::display($category->getDescription());
            }
        ?></textarea>
    </div>
    <div class="label" id="parent">
        <span class="titre">Parent :</span>
        <input
            class="firstInput fieldTypeSelecter"
            type="text"
            id="parent_category_name"
            name="parent_category_name"
            value="<?php
                if ($category != null && $category->getParent()!=null) {
                    Printer::display($category->getParent()->getName());
                } 
            ?>" />
        <input
            class="firstInput inputId"
            type="hidden"
            id="parent_category_id"
            name="parent_category_id"
            value="<?php
                if ($category != null && $category->getParent()!=null) {
                    Printer::display($category->getParent()->getId());
                }
            ?>" />
    </div>
    <input type="submit" value="OK" />
</form>
<script type="text/javascript">
    $(document).ready(function() {

        $("#parent_category_name").autocomplete({
            source: "?service=ListItemCategories&format=json",
            select: function(event, ui) {
                $("#parent_category_name").val(ui.item.label);
                $("#parent_category_id").val(ui.item.id);
            }
        });
    });
</script>
